<?php

namespace app\api\controller\wanlshop;

use addons\wanlshop\library\WanlSdk\Common;
use app\api\model\wanlshop\LifeEnd as WanlshopLifeEnd;
use app\api\model\wanlshop\Order;
use app\api\model\wanlshop\OrderGoods;
use app\api\model\wanlshop\Shop;
use app\api\model\wanlshop\Withdraw;
use app\common\controller\Api;
use app\common\library\token\driver\Redis;
use fast\Tree;
use think\Db;
use think\Log;
use think\Request;

class Store extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    public function index(Request $request)
    {
        $keyword = $request->param('keyword', '');
        $model = new Shop();
        if ($keyword !== '') {
            $model->where(function ($query) use ($keyword) {
                $query->whereOr('keywords', 'like', "%$keyword%")->whereOr('shopname', 'like', "%$keyword%");
                return $query;
            });
        }
        $data = $model->where([
            'verify' => '3',
            'status' => 'normal',
            'state2' => '1'
        ])
            ->whereNull('deletetime')
            ->order('id', 'DESC')
            ->order('weigh', 'DESC')
            ->paginate();
        $data->each(function ($item) {
            if ($item->avatar) {
                $item->avatar = cdnurl($item->avatar, true);
            } else {
                $item->avatar = cdnurl($item->avatar, true);
            }
            return $item;
        });
        return $this->success('', $data);
    }
}